// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import App from './App'
import router from './router'
import axios from 'axios'
import lazyload from 'vue-lazyload'
import infiniteScroll from 'vue-infinite-scroll'
import cookie from 'vue-cookie'
import { currency } from './util/currency'

Vue.config.productionTip = false
Vue.prototype.$ajax = axios;
Vue.use(Vuex);

// 懒加载
Vue.use(lazyload, {
    loading: "/static/loading-svg/loading-bars.svg"
});

// 无限滚动
Vue.use(infiniteScroll);

// 存取cookie
Vue.use(cookie);

// 价格格式化过滤器
Vue.filter("currency", currency);

//vuex
const store = new Vuex.Store({
    //要改变的数值
    state: {
        nickNmae: '',
        cartCount: 0
    },
    //用于改变state里的数，只有它能改变
    mutations:{
      updateUserInfo(state,nickName){
        state.nickName = nickName;
      },
      updateCartCount(state,cartCount){
        state.cartCount+=cartCount;
      },
    //  初始化购物车
      initCartCount(state,cartCount){
        state.cartCount = cartCount;
      }
    }
})

/* eslint-disable no-new */
new Vue({
    //挂载实例
    el: '#app',
    data: {},
    store,
    router,
    // template: '<App/>',
    // components: { App }
    // 渲染函数，替代template和components
    render: (h) => {
        return h(App);
    }
}).$mount("#app");
